package com.linkage.educloud.ah.bean;

import com.linkage.educloud.ah.data.CursorHelper;
import com.linkage.educloud.ah.data.Ws;

import org.json.JSONObject;

import java.util.List;

/**
 * <desc>
 * Created by The Moss on 2018/8/9.
 */

public class AccountData {
    String loginAccount;
    String loginpwd;
    String userName;
    long userId;
    String token;
    String phone;
    int userType;// 用户角色1:教师 2：学生 3：家长
    String avatar;
    int origin;// 用户来源：1.个人中心 2.校讯通
    long creditScore;// 积分数
    String creditScoreEndtime;// 积分有效期
    int isSign;// 是否已经签到（1、已签到，0未签到）
    long loginDate;
    int gradetype;
    int loginUser;//是否是登录状态用户1
    long lastLoginTime;
    List<Child> studentData;

    public static AccountData fromJSONObject(JSONObject jsonObj) {
        AccountData user = new AccountData();
        user.setUserId(jsonObj.optLong("userId"));
        user.setUserName(jsonObj.optString("userName"));
        user.setUserType(jsonObj.optInt("userType"));
        user.setAvatar(jsonObj.optString("avatar"));
        user.setToken(jsonObj.optString("token"));
        user.setOrigin(jsonObj.optInt("orgin"));
        user.setCreditScore(jsonObj.optLong("creditScore"));
        user.setIsSign(jsonObj.optInt("isSign"));
        user.setGradetype(jsonObj.optInt("schoolType"));
        user.setCreditScoreEndtime(jsonObj.optString("creditScoreEndtime"));
        user.setStudentData(Child.parseFromJsonForLogin(jsonObj
                .optJSONArray("studentData")));

        return user;
    }


    public static AccountData fromCursor(CursorHelper cursorHelper) {
        AccountData accountData = new AccountData();
        accountData.loginAccount = cursorHelper.getString(Ws.AccountTable.ACCOUNT_NAME);
        accountData.loginpwd = cursorHelper.getString(Ws.AccountTable.PASSWORD);
        accountData.userName = cursorHelper.getString(Ws.AccountTable.USER_NAME);
        accountData.userId = cursorHelper.getLong(Ws.AccountTable.USER_ID);
        accountData.userType = cursorHelper.getInt(Ws.AccountTable.USERTYPE);
        accountData.token = cursorHelper.getString(Ws.AccountTable.TOKEN);
        accountData.phone = cursorHelper.getString(Ws.AccountTable.PHONE);
        accountData.avatar = cursorHelper.getString(Ws.AccountTable.AVATAR);
        accountData.origin = cursorHelper.getInt(Ws.AccountTable.ORGIN);
        accountData.creditScore = cursorHelper.getInt(Ws.AccountTable.CREDITSCORE);
        accountData.creditScoreEndtime = cursorHelper.getString(Ws.AccountTable.CREDITSCORE_VILIDATE);
        accountData.isSign = cursorHelper.getInt(Ws.AccountTable.ISSIGN);
        accountData.gradetype = cursorHelper.getInt(Ws.AccountTable.GRADEID);
        accountData.loginUser = cursorHelper.getInt(Ws.AccountTable.ISLOGINING);
        accountData.lastLoginTime = cursorHelper.getInt(Ws.AccountTable.LAST_LOGIN);
        return accountData;
    }

    public String getLoginAccount() {
        return loginAccount;
    }

    public void setLoginAccount(String loginAccount) {
        this.loginAccount = loginAccount;
    }

    public String getLoginpwd() {
        return loginpwd;
    }

    public void setLoginpwd(String loginpwd) {
        this.loginpwd = loginpwd;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public int getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(int loginUser) {
        this.loginUser = loginUser;
    }

    public long getlastLoginTime() {
        return lastLoginTime;
    }

    public void setlastLoginTime(long lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public int getUserType() {
        return userType;
    }

    public void setUserType(int userType) {
        this.userType = userType;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public int getOrigin() {
        return origin;
    }

    public void setOrigin(int origin) {
        this.origin = origin;
    }

    public long getCreditScore() {
        return creditScore;
    }

    public void setCreditScore(long creditScore) {
        this.creditScore = creditScore;
    }

    public String getCreditScoreEndtime() {
        return creditScoreEndtime;
    }

    public void setCreditScoreEndtime(String creditScoreEndtime) {
        this.creditScoreEndtime = creditScoreEndtime;
    }

    public int getIsSign() {
        return isSign;
    }

    public void setIsSign(int isSign) {
        this.isSign = isSign;
    }

    public long getLoginDate() {
        return loginDate;
    }

    public void setLoginDate(long loginDate) {
        this.loginDate = loginDate;
    }

    public int getGradetype() {
        return gradetype;
    }

    public void setGradetype(int gradetype) {
        this.gradetype = gradetype;
    }

    public List<Child> getStudentData() {
        return studentData;
    }

    public void setStudentData(List<Child> studentData) {
        this.studentData = studentData;
    }

    @Override
    public String toString() {
        return "AccountData{" +
                "loginAccount='" + loginAccount + '\'' +
                ", loginpwd='" + loginpwd + '\'' +
                ", userName='" + userName + '\'' +
                ", userId=" + userId +
                ", token='" + token + '\'' +
                ", loginUser=" + loginUser +
                ", lastLoginTime=" + lastLoginTime +
                ", phone='" + phone + '\'' +
                ", userType=" + userType +
                ", avatar='" + avatar + '\'' +
                ", origin=" + origin +
                ", creditScore=" + creditScore +
                ", creditScoreEndtime='" + creditScoreEndtime + '\'' +
                ", isSign=" + isSign +
                ", loginDate=" + loginDate +
                ", gradetype=" + gradetype +
                ", studentData=" + studentData +
                '}';
    }
}
